package com.pan.kang.data.Impl;

import com.pan.kang.constant.MockTypeEnum;
import com.pan.kang.data.DataGenerator;
import com.pan.kang.model.TableSchema;
import com.pan.kang.util.FakerUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
 * 随机值数据生成器
 */
public class RandomDataGenerator implements DataGenerator {

    @Override
    public List<String> doGenerate(TableSchema.Field field, int rowNum) {
        String mockParams = field.getMockParams();
        List<String> list = new ArrayList<>(rowNum);
        for (int i = 0; i < rowNum; i++) {
            MockTypeEnum.ParamsTypeEnum randomTypeEnum = Optional.ofNullable(
                            MockTypeEnum.getParamsTypeByValue(mockParams))
                    .orElse(MockTypeEnum.ParamsTypeEnum.NAME);
            String randomString = FakerUtils.getRandomValue(randomTypeEnum);
            list.add(randomString);
        }
        return list;
    }
}
